package com.gitee.wsl.data.input.viewmodel.scopes


import com.gitee.wsl.coroutines.Queued
import com.gitee.wsl.data.input.interceptor.BallastInterceptorScope
import com.gitee.wsl.data.input.viewmodel.actors.EventActor
import com.gitee.wsl.data.input.viewmodel.actors.InputActor
import kotlinx.coroutines.CoroutineScope

internal class BallastInterceptorScopeImpl<Inputs : Any, Events : Any, State : Any>(
    interceptorCoroutineScope: CoroutineScope,

    override val hostViewModelType: String,
    override val hostViewModelName: String,
    override val initialState: State,

    private val inputActor: InputActor<Inputs, Events, State>,
    private val eventActor: EventActor<Inputs, Events, State>,
) : BallastInterceptorScope<Inputs, Events, State>,
    CoroutineScope by interceptorCoroutineScope {

    override suspend fun sendToQueue(queued: Queued<Inputs, Events, State>) {
        inputActor.enqueueQueued(queued, await = false)
    }

    override suspend fun postEvent(event: Events) {
        eventActor.enqueueEvent(event, null, false)
    }
}
